package com.kangdi.server.Exception;

import com.kangdi.server.pojo.RespBean;
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;


/**
 * 异常处理类
 */
@RestControllerAdvice
public class GeltException {
    @ExceptionHandler(SQLException.class)
    public RespBean myException(SQLException e){
        if (e instanceof SQLIntegrityConstraintViolationException){
            return RespBean.error("该数据关联了其他数据，操作失败");
        }
        return RespBean.error("数据库异常，操作失败");
    }
}
